/**
 * @param {string} s
 * @return {number}
 */
var lengthOfLongestSubstring = function(s) {
    let str = '';
    let max = 0;
    for(let c of s) {
        const index = str.indexOf(c);
        if(index !== -1) {
            max = Math.max(str.length, max);
            str = str.substring(index + 1)
        }
        str += c;
    }
    return Math.max(str.length, max);
};

console.log(lengthOfLongestSubstring('abcabcbb'))
console.log(lengthOfLongestSubstring('bbbbb'))
console.log(lengthOfLongestSubstring('pwwkew'))